<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/global.css" media="all">
    <script type="text/javascript" src="/plugins/layui/layui.js"></script>
    <title>交易所时间维度新增</title>
    <style type="text/css">
        .searcheBottom{margin-bottom: 10px;}
    </style>
</head>
<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        <div class="demoTable">
            <div class="layui-inline searcheBottom">
                <div class="layui-inline" style="margin-right: 30px;">
                    <h3><b>当前交易所：${exchangeName!}</b></h3>
                    <input id="exchangeId" name="exchangeId" class="layui-input" style="display: none" value="${id!}"/>
                </div>
            </div>
            <div class="layui-inline searcheBottom">
                时间维度名称：
                <div class="layui-inline">
                    <input id="dimensionName" class="layui-input" name="dimensionName" autocomplete="off" placeholder="时间维度名称"/>
                </div>
            </div>
            <div class="layui-inline searcheBottom">
                <a class="layui-btn" data-type="reload" id="search">搜索</a>
                <a class="layui-btn layui-btn-primary" id="reset">重置</a>
                <button id="traadd" class="layui-btn">添加</button>
                <a href="/manage/latmdle/latmdlelist?id=${id!}&exchangeName=${exchangeName!}" class="layui-btn" style="float: right;">返回</a>
            </div>
        </div>
    </blockquote>
    <span style="font-size: 16px;"><b>交易对列表</b></span>
    <table class="layui-hide" id="latTable" lay-filter="tableFilter"></table>
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script>
    layui.use(['jquery','table','laydate','layer','form','util'],function(){
        var $=layui.jquery,table=layui.table,laydate = layui.laydate,
            layer = layui.layer,form = layui.form,util=layui.util;
        var exchangeId =parseInt("${id!}");//获取交易所id
        //表格渲染
        pageInit();
        function pageInit() {
            table.render({
                elem:"#latTable",
                url:"/manage/latmdle/selexchangelat",
                where:{exchangeId:exchangeId},
                method:"post",
                cols:[[
                    {type:'checkbox'},
                    {field:'id', title: 'ID', sort: true,align:'center'},
                    {field:'dimensionName', title: '时间维度名称',align:'center'},
                    {field:'createTime', title: '添加时间',sort: true,align:'center',
                        templet: function(d){
                            return util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss');
                        }
                    }
                ]],
                limits:[10,15,20,25,30],
                limit:10,
                page:true
            });
        }

        //表格重载
        var active = {
            reload: function () {
                var dimensionName = $('#dimensionName');
                var exchangeId = $('#exchangeId');
                table.reload('latTable', {
                    where: {
                        dimensionName: dimensionName.val(),
                        exchangeId:exchangeId.val()
                    }
                });
            }
        };

        //将搜索框的值随请求传到后台
        $('.demoTable #search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $("input").keydown(function (e) {
            if(e.keyCode == 13){
                $('#search').click();
            }
        });
        //重置
        $("#reset").on("click",function(){
            dimensionName.value = '';
        });

        $('#traadd').on('click', function(){
            var checkStatus = table.checkStatus('latTable')
                ,data = checkStatus.data;
            var checkList = JSON.stringify(data);
            if(data.length < 1){
                layer.msg('请选择数据', { icon: 7, shift: 6 });
            }else {
                $.ajax({
                    url:"/manage/latmdle/addexchangelat",
                    type:"post",
                    data:{"checkList":checkList,"exchangeId":$('#exchangeId').val()},
                    dataType:"json",
                    success:function (res) {
                        if(res.code ==0){
                            layer.msg(res.msg, { icon: 6, shift: 6 });
                            pageInit();
                        }
                    }
                })
            }
        });
    });

</script>
</body>
</html>